Follow-up on #1352#1519
Conversation
|
So the main goal imo here is to avoid implementing anything in the runtime code (or at least minimize the amount of required code). That's because we'll have at least 5 runtimes (soon) with such extensions and it'll be hard to maintain it. If you'd find solution for that, it would be perfect :) |
Signed-off-by: Serban Iorga <serban@parity.io>
Signed-off-by: Serban Iorga <serban@parity.io>
I pushed a new version that minimizes the amount of code implemented in the runtime and also leads to using a single macro instead of 3. Sorry, I force-pushed, I got lost in all the changes. I couldn't leverage
Could you expand on this please ? We can implement |
That's fine :) Seems great, thanks a lot! I'll take another look later. Yeah - I have also failed to avoid using macro at all, but your version looks much better to me!
There's
I was thinking about something like that: // every pallet implements `Contains<Call>` or some similar trait:
impl<T, I> Contains<Call> for pallet_bridge_parachains::Pallet<T, I> {
fn contains(call: &Call) -> bool {
// do validation here
}
}
// Cotnains is implemented for tuples, so given that we have impl Contains<Call> for our three pallets, we may then make a tuple e.g. `(pallet_bridge_parachains::Pallet<Runtime, WithRialtoParachainsInstance>, pallet_bridge_grandpa::Pallet<Runtime, WithRialtoGrandpaInstance>)` and it would also implement a Contains<Call>. So we can use something like that:
struct OurGreatExtension<C, F: Contains<Call>>;
impl SignedExtensions for OurGreatExtension<C, F: Contains<Call>> {
fn do-verification-or-how-it-is-called(call: &Call) -> bool {
if F::contains(call) {
return transaction-is-outdated-error;
}
}
}
// and finally use something like that in the runtime:
type SignedExtension = (
...
OurGreatExtension<Call, (pallet_bridge_parachains::Pallet<Runtime, WithRialtoParachainsInstance>, pallet_bridge_grandpa::Pallet<Runtime, WithRialtoGrandpaInstance>)>
...
);I have attempted that, but back then I have failed to climb down from runtime |
The problem with
Oh, this can really work. I can give it a try. |
I did some small experiments and now the problem is that |
svyatonik
left a comment
There was a problem hiding this comment.
Looks much better than my version, thank you! :)
An alternative solution to using macros like
declare_bridge_reject_obsolete_grandpa_header().The current PR implements this approach only for the grandpa headers validation. If the feedback is positive, we can extend this to parachains and messages.
It looks like we don't have enough slots in
SignedPayloadto have aSignedExtensionimplementation for each validator, so I created an aggregated validator that implementsSignedExtension.Starting from here we could variate the approach. For example we could have a macro that generates the structures that implement
RejectObsoleteGrandpaHeaderand theSignedExtensionimplementation that aggregates all validations. I think we could also useimpl_for_tuplesas suggested here.Posting this PR to gather feedback on the general idea. I might need to add some comments and do some polishing.